package com.sks.web.action.district;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.stereotype.Controller;

import com.sks.bean.PageView;
import com.sks.bean.pojo.Favorites;
import com.sks.service.house.BuildingService;
import com.sks.service.house.FavoritesService;
import com.sks.service.house.HouseService;
import com.sks.utils.WebUtil;
import com.sks.web.action.BasicAction;
import com.sks.web.formbean.house.FavoritesForm;


/**
 * 个人中心收藏功能
 * @author yuanjiayuan
 *
 */
@Controller("/sks/districtFavorites")
public class DistrictFavorites extends BasicAction{

	@Resource(name = "favoritesServiceBean") private FavoritesService favoritiesService;

	
	public ActionForward favoritesList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		//获取小区
		FavoritesForm formbean = (FavoritesForm) form;
		StringBuffer build = new StringBuffer(" o.user.userId = '" + WebUtil.getUsers(request).getUserId() + "'");
		build.append(" and o.building.buildingId is not null");
		PageView<Favorites> pv = new PageView<Favorites>(formbean.getPageSize(), 0);
	    pv.setQueryResult(favoritiesService.getScrollData(0, pv.getMaxresult(), build.toString(),null , null));	    
	    request.setAttribute("buildNum", pv.getTotalrecord());  
	    request.setAttribute("pv", pv);  
	    
	    
	    //获取房源
	    StringBuffer house = new StringBuffer(" o.user.userId = '" + WebUtil.getUsers(request).getUserId() + "'");
	    house.append(" and o.house.houseId is not null");
		PageView<Favorites> page = new PageView<Favorites>(formbean.getPageSize(), 0);
		page.setQueryResult(favoritiesService.getScrollData(0, pv.getMaxresult(), house.toString(),null , null)); 
		request.setAttribute("houseNum", page.getTotalrecord());
		request.setAttribute("page", page);
	    
	    
	    return mapping.findForward("favorites");
	}
}
